import json

from api.base_service import BaseService


class OrderSettingService(BaseService):
    def __init__(self):
        super(OrderSettingService, self).__init__()
        self.service_name = "OrderSettingService"
    def add(self,order_settings):
        resp = self.dubbo_client.invoke(self.service_name,"add",order_settings)
        if resp == "null":
            return True
        else:
            return False
    def get_order_setting_by_month(self,month):
        resp = self.dubbo_client.invoke(self.service_name,"getOrderSettingByMonth",month)
        return json.loads(resp)
    def edit_number_by_date(self,order_setting):
        order_setting["class"] = "com.itheima.pojo.OrderSetting"
        resp = self.dubbo_client.invoke(self.service_name,"editNumberByDate",order_setting)
        if resp == "null":
            return True
        else:
            return False
if __name__ == '__main__':
    order_settings = [{"orderDate": "2025-09-17 10:01:01", "number": 2000}]
    oss = OrderSettingService()
    result = oss.add(order_settings)
    print(result)
    get_order = OrderSettingService()
    result = get_order.get_order_setting_by_month("2022-09")
    print(result)
    order_setting = {
                    "orderDate": "2021-09-17 10:01:01",
                    "number": 2000
                }
    edit_number = OrderSettingService()
    result = edit_number.edit_number_by_date(order_setting)
    print(result)